﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

//找不同
//https://leetcode.cn/problems/find-the-difference/submissions/
class Solution {
public:
    char findTheDifference(string s, string t) {
        unordered_map<char,int> m;
        for(const auto& c:s) ++m[c];

        for(const auto& c:t)
        {
            if(!m.count(c)) return c;
            --m[c];
            if(m[c] == 0) m.erase(c);
        }
        return 0;
    }
};

//长度为三且各字符不同的子字符串
//https://leetcode.cn/problems/substrings-of-size-three-with-distinct-characters/description/
class Solution {
public:
    int countGoodSubstrings(string s) {
        int n = s.size();
        int count = 0;
        for(int i = 2;i < n;++i)
        {
            if(s[i-2] != s[i-1] &&
               s[i-1] != s[i]   &&
               s[i-2] != s[i])
               ++count;
        }
        return count;
    }
};

